package model

import (
	"gorm.io/plugin/soft_delete"
	"time"
)

type BaseModel struct {
	ID        uint64                `gorm:"primarykey;comment:主键"`
	CreateAt  time.Time             `gorm:"column:create_time;autoCreateTime;comment:创建时间"`
	UpdateAt  time.Time             `gorm:"column:update_time;autoUpdateTime;comment:更新时间"`
	IsDeleted soft_delete.DeletedAt `gorm:"type:int(1);not null;softDelete:flag,DeletedAtField:DeletedAt;default:0;comment:0未删除1删除"`
	Status    int32                 `gorm:"type:int(1);not null;default:1;comment:0未发布1发布"`
	// 忽略该字段，- 表示无读写，-:migration 表示无迁移权限，-:all 表示无读写迁移权限
	//Children any `gorm:"-" json:"children"`
}

// 购物车
type ShoppingCart struct {
	BaseModel
	UserId  uint64 `gorm:"type:bigint;index;not null;comment:用户ID"`
	GoodsId uint64 `gorm:"type:bigint;index;not null;comment:购买商品"`
	Nums    int32  `gorm:"type:int;not null;comment:购买数量"`
	Checked bool   `gorm:"not null;comment:选中状态"`
}

func (c *ShoppingCart) TableName() string {
	return "ksd_shopping_cart"
}

// 订单表
type OrderInfo struct {
	BaseModel
	OrderNo     string    `gorm:"type:varchar(100);not null;index;default:'';comment:订单编号"`
	TradeNo     string    `gorm:"type:varchar(100);not null;index;default:'';comment:交易号"`
	PayType     int32     `gorm:"type:int;default:1;not null;comment:支付方式 1支付宝 2微信"`
	OrderStatus string    `gorm:"type:varchar(20);not null;comment:PAYING（待支付）TRADE_SUCCESS（支付成功）;TRADE_CLOSED（超时关闭）TRADE_FINISHED（交易结束）"`
	OrderPrice  float32   `gorm:"type:float;not null;comment:支付金额"`
	PayTime     time.Time `gorm:"type:datetime;not null;comment:支付时间"`
	UserId      uint64    `gorm:"type:bigint;index;not null;comment:用户ID"`
	Address     string    `gorm:"type:varchar(100);default:'';comment:收件人地址"`
	SingerName  string    `gorm:"type:varchar(40);default:'';comment:收件人名称"`
	SingerPhone string    `gorm:"type:varchar(11);default:'';comment:收件人电话"`
	Post        string    `gorm:"type:varchar(20);default:'';comment:收件人邮编"`
}

func (c *OrderInfo) TableName() string {
	return "ksd_goods_order"
}

// 订单商品表
type OrderGoodsInfo struct {
	BaseModel
	GoodsId uint64 `gorm:"type:bigint;not null;index;comment:购买商品"`
	OrderId uint64 `gorm:"type:varchar(40);not null;index;comment:订单编号"`

	// 冗余商品信息，解决跨服务调用的问题，所以高并发系统中我们一般都不回遵循三范式。可以作为镜像数据。
	GoodsName  string  `gorm:"type:varchar(100);not null;default:'';comment:商品名称"`
	GoodsImage string  `gorm:"type:varchar(200);not null;default:'';comment:商品封面"`
	GoodsPrice float32 `gorm:"type:float;default:0;not null;comment:商品价格"`
	GoodsDesc  string  `gorm:"type:varchar(200);not null;default:'';comment:商品描述"`
	Nums       int32   `gorm:"type:int;default:0;not null;comment:商品数量"`
}

func (c *OrderGoodsInfo) TableName() string {
	return "ksd_goods_order_detail"
}
